package com.ruoyi.equipment.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.equipment.domain.Equipment;
import com.ruoyi.equipment.mapper.EquipmentStandingBookMapper;
import com.ruoyi.equipment.domain.EquipmentStandingBook;
import com.ruoyi.equipment.service.IEquipmentStandingBookService;

/**
 * 设备台账维护Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-12-14
 */
@Service
public class EquipmentStandingBookServiceImpl implements IEquipmentStandingBookService 
{
    @Autowired
    private EquipmentStandingBookMapper equipmentStandingBookMapper;

    /**
     * 查询设备台账维护
     * 
     * @param id 设备台账维护主键
     * @return 设备台账维护
     */
    @Override
    public EquipmentStandingBook selectEquipmentStandingBookById(Long id)
    {
        return equipmentStandingBookMapper.selectEquipmentStandingBookById(id);
    }

    /**
     * 查询设备台账维护列表
     * 
     * @param equipmentStandingBook 设备台账维护
     * @return 设备台账维护
     */
    @Override
    public List<EquipmentStandingBook> selectEquipmentStandingBookList(EquipmentStandingBook equipmentStandingBook)
    {
        return equipmentStandingBookMapper.selectEquipmentStandingBookList(equipmentStandingBook);
    }

    /**
     * 新增设备台账维护
     * 
     * @param equipmentStandingBook 设备台账维护
     * @return 结果
     */
    @Transactional
    @Override
    public int insertEquipmentStandingBook(EquipmentStandingBook equipmentStandingBook)
    {
        int rows = equipmentStandingBookMapper.insertEquipmentStandingBook(equipmentStandingBook);
        insertEquipment(equipmentStandingBook);
        return rows;
    }

    /**
     * 修改设备台账维护
     * 
     * @param equipmentStandingBook 设备台账维护
     * @return 结果
     */
    @Transactional
    @Override
    public int updateEquipmentStandingBook(EquipmentStandingBook equipmentStandingBook)
    {

        return equipmentStandingBookMapper.updateEquipmentStandingBook(equipmentStandingBook);
    }

    /**
     * 批量删除设备台账维护
     * 
     * @param ids 需要删除的设备台账维护主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteEquipmentStandingBookByIds(Long[] ids)
    {
        equipmentStandingBookMapper.deleteEquipmentByIds(ids);
        return equipmentStandingBookMapper.deleteEquipmentStandingBookByIds(ids);
    }

    /**
     * 删除设备台账维护信息
     * 
     * @param id 设备台账维护主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteEquipmentStandingBookById(Long id)
    {
        equipmentStandingBookMapper.deleteEquipmentById(id);
        return equipmentStandingBookMapper.deleteEquipmentStandingBookById(id);
    }

    /**
     * 新增${subTable.functionName}信息
     * 
     * @param equipmentStandingBook 设备台账维护对象
     */
    public void insertEquipment(EquipmentStandingBook equipmentStandingBook)
    {
        List<Equipment> equipmentList = equipmentStandingBook.getEquipmentList();
        Long id = equipmentStandingBook.getId();
        if (StringUtils.isNotNull(equipmentList))
        {
            List<Equipment> list = new ArrayList<Equipment>();
            for (Equipment equipment : equipmentList)
            {
                equipment.setId(id);
                list.add(equipment);
            }
            if (list.size() > 0)
            {
                equipmentStandingBookMapper.batchEquipment(list);
            }
        }
    }
}
